package com.bw.unit3.uitl

import android.content.Context
import androidx.room.Room
import com.bw.unit3.db.ShoppingDb

/**
 *
 * @ClassName: DBUtil
 * @Description: java类作用描述
 * @Author: zhangyanchao
 * @CreateDate: 2024/9/13 9:58 AM
 * @Version: 1.0
 */
class DBUtil {
    //伴生对象
    companion object {
        //里面的字段或者方法，可以直接通过DBUtil 来调用
        lateinit var shoppingDb: ShoppingDb
        fun init(context: Context) {
            shoppingDb = Room.databaseBuilder(context, ShoppingDb::class.java, "shopping.db")
                .allowMainThreadQueries()//允许在主线程操作数据库
                .build()
        }

        fun getShopDb(): ShoppingDb {
            return shoppingDb
        }
    }
}